//
//  CYWenDaDetailViewController.m
//  cyydt
//
//  Created by chu on 2019/1/27.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYWenDaDetailViewController.h"
#import "CYWenDaDetail_WenTiTableViewCell.h"
#import "CYWenDaDetail_HuiFuTableViewCell.h"
#import "CYYaoQingHuiDaViewController.h"
#import "CYPubilishQuestionViewController.h"
#import "CYWenDaDiCengViewController.h"

@interface CYWenDaDetailViewController ()<UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate, PlatformButtonClickDelegate>
{
    UIButton *_collectionBtn;
    UIImage *_shareImage;

}
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataSourceArr;

@property (nonatomic, strong) CYProjectModel *wentiModel;

@property (nonatomic, strong) UIView *bottomView;

@property (nonatomic, strong) UIView *tableFooterView;



@end

@implementation CYWenDaDetailViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"问答详情";
//    NSMutableDictionary *muDic = [self.model mj_keyValues];
//    [muDic setObject:[NSNumber numberWithBool:NO] forKey:@"isOpen"];
//    self.wentiModel = [CYProjectModel mj_objectWithKeyValues:muDic];
    
//    [self.view addSubview:self.bottomView];
    [self.view addSubview:self.tableView];

    [self getData];
    self.tableView.estimatedRowHeight = 40;
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self RightsetupNavgationItemWithpictureName:@"zxxq_gengd"];
    
    
}

- (void)RighttouchEvent{
    YSActionSheetView * ysSheet=[[YSActionSheetView alloc]initNYSView];
    ysSheet.delegate=self;
    [[UIApplication sharedApplication].keyWindow addSubview:ysSheet];
}

- (void) customActionSheetButtonClick:(YSActionSheetButton *) btn
{
    [self shareImageToPlatformType:btn.tag];
}

- (void)shareImageToPlatformType:(NSInteger)platformType
{
    //2:qq 3:qzone 0:weixin 1:pengyouquan
    //创建分享消息对象
    if (platformType == 2 || platformType == 3) {
        
        NSString *utf8String = self.wentiModel.share_url;
        NSString *title = self.wentiModel.title;
        NSString *shareContent = @"";
        if ([NSString stringIsNull:self.wentiModel.shareContent]) {
            shareContent = self.wentiModel.shareContent;
        }else{
            shareContent = [NSString stringWithFormat:@"%@个回答，%@人收藏", self.wentiModel.answer_number, self.wentiModel.collect_number];
        }
        NSString *description = shareContent;
        UIImage *image = nil;
        if (!_shareImage) {
            image = [UIImage imageNamed:@"login_logo"];
        }else{
            image = _shareImage;
        }
        QQApiNewsObject *newsObj = [QQApiNewsObject
                                    objectWithURL:[NSURL URLWithString:utf8String] title:title description:description previewImageData:UIImageJPEGRepresentation(image, 1)];
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
        if (platformType == 2) {
            //将内容分享到qq
            [QQApiInterface sendReq:req];
        }else{
            //将内容分享到qzone
            [QQApiInterface SendReqToQZone:req];
        }
        
    }else{
        SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
        // 是否是文档
        req1.bText =  NO;
        
        //    WXSceneSession  = 0,        /**< 聊天界面    */
        //    WXSceneTimeline = 1,        /**< 朋友圈      */
        //    WXSceneFavorite = 2,
        
        
        req1.scene = (int)platformType;
        
        //创建分享内容对象
        WXMediaMessage *urlMessage = [WXMediaMessage message];
        urlMessage.title = self.wentiModel.title;//分享标题
        NSString *shareContent = @"";
        if ([NSString stringIsNull:self.wentiModel.shareContent]) {
            shareContent = self.wentiModel.shareContent;
        }else{
            shareContent = [NSString stringWithFormat:@"%@个回答，%@人收藏", self.wentiModel.answer_number, self.wentiModel.collect_number];
        }
        urlMessage.description = shareContent;//分享描述
        if (!_shareImage) {
            [urlMessage setThumbImage:[UIImage imageNamed:@"login_logo"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }else{
            [urlMessage setThumbImage:_shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }
        
        //创建多媒体对象
        WXWebpageObject *webObj = [WXWebpageObject object];
        webObj.webpageUrl = self.wentiModel.share_url;//分享链接
        
        //完成发送对象实例
        urlMessage.mediaObject = webObj;
        req1.message = urlMessage;
        
        //发送分享信息
        [WXApi sendReq:req1];
        
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    return self.dataSourceArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        //导师推荐
        CYWenDaDetail_WenTiTableViewCell *cell = [CYWenDaDetail_WenTiTableViewCell initWithTableView:tableView Identifier:@"CYWenDaDetail_WenTiTableViewCell"];
        cell.model = self.wentiModel;
        __weak typeof(self)weakself = self;
        cell.block = ^{
            if ([weakself.wentiModel.isOpen boolValue]) {
                weakself.wentiModel.isOpen = [NSNumber numberWithBool:NO];
            }else{
                weakself.wentiModel.isOpen = [NSNumber numberWithBool:YES];
            }
            [weakself.tableView reloadData];
        };
        cell.guanzhuBlock = ^{
            if ([self.wentiModel.is_follow integerValue] == 1) {
                [self cancleguanzhu];
            }else{
                [self guanzhu];
            }
        };
        return cell;
    }else{
        CYWenDaDetail_HuiFuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYWenDaDetail_HuiFuTableViewCell"];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"CYWenDaDetail_HuiFuTableViewCell" owner:nil options:nil][0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = self.dataSourceArr[indexPath.row];
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        CYWenDaDetail_WenTiTableViewCell *cell = [CYWenDaDetail_WenTiTableViewCell initWithTableView:tableView Identifier:@"CYWenDaDetail_WenTiTableViewCell"];
        cell.model = self.wentiModel;
        return cell.cellHeight;
    }
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        CYWenDaDiCengViewController *wenda = [[CYWenDaDiCengViewController alloc] init];
        wenda.questionModel = self.wentiModel;
        wenda.huidaModel = self.dataSourceArr[indexPath.row];
        [[AppDelegate sharedAppDelegate] pushViewController:wenda];
    }
}


- (void)getData{
    self.page = 1;
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"ask/index"];
    NSDictionary *param = @{@"id":self.wedaId};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"精品问答 ---- %@",responseResult);
        if ([self.tableView.mj_header isRefreshing]) {
            [self.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *data = responseResult[@"data"];
                    NSArray *list = data[@"list"];
                    [self.dataSourceArr removeAllObjects];
                    for (NSDictionary *dic in list) {
                        CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                        [self.dataSourceArr addObject:model];
                    }
                    if (self.dataSourceArr.count == 0) {
                        self.tableView.tableFooterView = self.tableFooterView;
                    }else{
                        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 0.1)];
                    }
                    if (data[@"question"] && [data[@"question"] isKindOfClass:[NSDictionary class]]) {
                        NSDictionary *question = data[@"question"];
                        NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:question];
                        [muDic setObject:[NSNumber numberWithBool:NO] forKey:@"isOpen"];
                        self.wentiModel = [CYProjectModel mj_objectWithKeyValues:muDic];
                    }
                    [self.bottomView removeFromSuperview];
                    [self.view addSubview:self.bottomView];
                    [self initCollectionBtnStates];
                    [self.tableView reloadData];
                    if (self.wentiModel.img_url.count > 0) {
                        NSString *url = [self.wentiModel.img_url firstObject];
                        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:url] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                            
                        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
                            self->_shareImage = image;
                        }];
                    }
                }
            }else{
                [self.view makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

- (void)getMoreData{
    self.page ++;
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"ask/index"];
    NSDictionary *param = @{@"id":self.wedaId, @"page":[NSNumber numberWithInteger:self.page]};
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"精品问答 ---- %@",responseResult);
        if ([self.tableView.mj_footer isRefreshing]) {
            [self.tableView.mj_footer endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
            self.page --;
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *data = responseResult[@"data"];
                    NSArray *list = data[@"list"];
                    for (NSDictionary *dic in list) {
                        CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                        [self.dataSourceArr addObject:model];
                    }
                    [self.tableView reloadData];
                }
            }else{
                self.page --;
                [self.view makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - DZNEmptyDataSetDelegate
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"wuneir"];
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *title = @"当前页面没有内容！";
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:RGBOF(0x999999)
                                 };
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    // 空白页面被点击时开启动画，reloadEmptyDataSet
    [self getData];
}

- (UITableView *)tableView{
    if (!_tableView) {
        if (HX_IS_IPhoneX_All) {
            _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - Height_NavBar - 83) style:UITableViewStyleGrouped];

        }else{
            _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - Height_NavBar - 48) style:UITableViewStyleGrouped];
        }
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackGroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getData];
        }];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [self getMoreData];
        }];
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        
        [_tableView registerNib:[UINib nibWithNibName:@"CYWenDaDetail_WenTiTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYWenDaDetail_WenTiTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYWenDaDetail_HuiFuTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYWenDaDetail_HuiFuTableViewCell"];
        
    }
    return _tableView;
}

- (NSMutableArray *)dataSourceArr{
    if (!_dataSourceArr) {
        _dataSourceArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataSourceArr;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        if (HX_IS_IPhoneX_All) {
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 83, kWindowW, 83);
        }else{
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 48 , kWindowW, 48);
        }
        
        UIView *contrainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 48)];
        [_bottomView addSubview:contrainerView];
        
        if (self.wentiModel && self.wentiModel.wsurl && ![NSString stringIsNull:self.wentiModel.wsurl]) {
            NSArray *images = @[@"wdxq_yq", @"wdxq_sc", @"wdxq_zx", @"wdxq_hd"];
            NSArray *titles = @[@"邀请回答", @"收藏问题", @"在线咨询", @"我来回答"];
            for (int i = 0; i < titles.count; i++) {
                LPButton *btn = [[LPButton alloc] init];
                btn.style = LPButtonStyleTop;
                btn.frame =CGRectMake(i * (kWindowW / 4), 0, kWindowW / 4, 48);
                btn.space = 5;
                [btn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
                [btn setTitle:titles[i] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:11];
                if (i == 0) {
                    [btn setTitleColor:RGBOF(0x666666) forState:UIControlStateNormal];
                    [btn setBackgroundColor:[UIColor whiteColor]];
                }else if (i == 1){
                    [btn setTitleColor:RGBOF(0x666666) forState:UIControlStateNormal];
                    [btn setBackgroundColor:[UIColor whiteColor]];
                    [btn setImage:[UIImage imageNamed:@"wdxq_scxz"] forState:UIControlStateSelected];
                    _collectionBtn = btn;
                }else if (i == 2){
                    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [btn setBackgroundColor:RGBOF(0xFAB55B)];
                }else{
                    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
                    [btn setBackgroundColor:RGBOF(0xF96767)];
                    
                }
                btn.tag = i;
                [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
                [contrainerView addSubview:btn];
            }
        }else{
            NSArray *images = @[@"wdxq_yq", @"wdxq_sc", @"wdxq_hd"];
            NSArray *titles = @[@"邀请回答", @"收藏问题", @"我来回答"];
            for (int i = 0; i < titles.count; i++) {
                LPButton *btn = [[LPButton alloc] init];
                btn.style = LPButtonStyleTop;
                btn.frame =CGRectMake(i * (kWindowW / titles.count), 0, kWindowW / titles.count, 48);
                btn.space = 5;
                [btn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
                [btn setTitle:titles[i] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:11];
                if (i == 0) {
                    [btn setTitleColor:RGBOF(0x666666) forState:UIControlStateNormal];
                    [btn setBackgroundColor:[UIColor whiteColor]];
                }else if (i == 1){
                    [btn setTitleColor:RGBOF(0x666666) forState:UIControlStateNormal];
                    [btn setBackgroundColor:[UIColor whiteColor]];
                    [btn setImage:[UIImage imageNamed:@"wdxq_scxz"] forState:UIControlStateSelected];
                    _collectionBtn = btn;
                }else{
                    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
                    [btn setBackgroundColor:RGBOF(0xF96767)];
                    
                }
                btn.tag = i;
                [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
                [contrainerView addSubview:btn];
            }
        }
        
    }
    return _bottomView;
}


- (void)btnClick:(UIButton *)sender{
    if (sender.tag == 0) {
        //邀请回答
        CYYaoQingHuiDaViewController *yaoqing = [[CYYaoQingHuiDaViewController alloc] init];
        yaoqing.questionId = self.wentiModel.ID;
        yaoqing.cateId = self.wentiModel.big_catid;
        yaoqing.model = self.wentiModel;
        [[AppDelegate sharedAppDelegate] pushViewController:yaoqing];
    }else if (sender.tag == 1){
        //收藏问题
        if ([self.wentiModel.is_collect integerValue] == 1) {
            //一收藏
            [self cancleCollection];
        }else{
            [self collection];
        }
    }else if (sender.tag == 2){
        if ([sender.titleLabel.text isEqualToString:@"我来回答"]) {
            //我来回答
            CYPubilishQuestionViewController *huida = [[CYPubilishQuestionViewController alloc] init];
            huida.type = TiWenType_WoLaiHuiDa;
            huida.biaoti = self.wentiModel.title;
            huida.questionId = self.wentiModel.ID;
            [[AppDelegate sharedAppDelegate] pushViewController:huida];
        }else{
            //在线聊天
            CYChatViewController *chat = [[CYChatViewController alloc] init];
            chat.url = [NSString stringWithFormat:@"%@?device=ios",self.wentiModel.wsurl];
            [[AppDelegate sharedAppDelegate] pushViewController:chat];
        }
//        if (self.wentiModel && self.wentiModel.wsurl && ![NSString stringIsNull:self.wentiModel.wsurl]) {
//            //在线聊天
//            CYChatViewController *chat = [[CYChatViewController alloc] init];
//            chat.url = [NSString stringWithFormat:@"%@?device=ios",self.wentiModel.wsurl];
//            [[AppDelegate sharedAppDelegate] pushViewController:chat];
//        }else{
//            //我来回答
//            CYPubilishQuestionViewController *huida = [[CYPubilishQuestionViewController alloc] init];
//            huida.type = TiWenType_WoLaiHuiDa;
//            huida.biaoti = self.wentiModel.title;
//            huida.questionId = self.wentiModel.ID;
//            [[AppDelegate sharedAppDelegate] pushViewController:huida];
//        }
        
    }else{
        //我来回答
        CYPubilishQuestionViewController *huida = [[CYPubilishQuestionViewController alloc] init];
        huida.type = TiWenType_WoLaiHuiDa;
        huida.biaoti = self.wentiModel.title;
        huida.questionId = self.wentiModel.ID;
        [[AppDelegate sharedAppDelegate] pushViewController:huida];

    }
}

#pragma mark - 收藏取消收藏
- (void)cancleCollection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"collection",self.wentiModel.ID];
    NSDictionary *param = @{@"type":@"4", @"articleId":self.wentiModel.ID};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消收藏 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.wentiModel.is_collect = [NSNumber numberWithInteger:2];
                self->_collectionBtn.selected = NO;
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)collection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"collection/addCollect"];
    NSDictionary *param = @{@"type":@4, @"articleId":self.wentiModel.ID};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"收藏本咨询 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.wentiModel.is_collect = [NSNumber numberWithInteger:1];
                self->_collectionBtn.selected = YES;
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}

- (void)initCollectionBtnStates{
    if ([self.wentiModel.is_collect integerValue] == 1) {
        _collectionBtn.selected = YES;
    }else{
        _collectionBtn.selected = NO;
    }
}

#pragma mark - 关注
- (void)guanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"attention"];
    NSDictionary *param = @{@"toUserId":self.wentiModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"添加关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.wentiModel.is_follow = [NSNumber numberWithInteger:1];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

- (void)cancleguanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"attention", self.wentiModel.user_id];
    NSDictionary *param = @{@"userId":self.wentiModel.user_id};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"取消关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                self.wentiModel.is_follow = [NSNumber numberWithInteger:2];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

- (UIView *)tableFooterView{
    if (!_tableFooterView) {
        _tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 260)];
        
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wuneir"]];
        imageView.frame = CGRectMake(0, 50, kWindowW, 160);
        imageView.contentMode = UIViewContentModeCenter;
        [_tableFooterView addSubview:imageView];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 30, kWindowW, 20)];
        label.text = @"暂无相关内容";
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:16];
        label.textColor = RGBOF(0x999999);
        [_tableFooterView addSubview:label];
    }
    return _tableFooterView;
}

@end
